package com.axx.android.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by chowtoni on 16/10/8.
 */
public class GsonUtils {
    public static <T> T fromJson(String json, TypeToken<T> t) throws JSONException {
        Gson gson = new Gson();
        T t1;
        try {
            t1 = gson.fromJson(json, t.getType());
            return t1;
        } catch (Exception e) {
            e.printStackTrace();
            throw new JSONException("json 解析错误");
        }
    }

    public static String toJson(Object object) {
        Gson gson = new Gson();
        return gson.toJson(object);
    }
}
